﻿using AutoMapper;
using Modules;
using Modules.CheckIn.Entitys;
using Modules.Person;
using PmSoft;

namespace ManagementApi.Models.Manage.CheckIn
{
    public class CheckInDetailForm : CheckInDetailEditForm
    {
        /// <summary>
        /// 进出场标识
        /// </summary>
        public string EntryExitMarkName { get; set; }
        /// <summary>
        /// 人员姓名
        /// </summary>
        public string PersonName { get; set; }
    }

    public static partial class CheckInDetailExceptions
    {
        public static CheckInDetailForm AsForm(this CheckInDetail entity)
        {
            CheckInDetailForm checkInDetailForm = new CheckInDetailForm();
            var mapper = ServiceAccessor.GetService<IMapper>();
            mapper.Map(entity, checkInDetailForm);
            checkInDetailForm.EntryExitMarkName = entity.EntryExitMark.GetDescription();
            var personService = ServiceAccessor.GetService<PersonService>();
            var personInfo = personService.GetPerson(entity.PersonId);
            checkInDetailForm.PersonName = personInfo?.Name ?? string.Empty;
            return checkInDetailForm;
        }
    }
}
